import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        //逆序数组
        int[] array = new int[]{1,2,3,4};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main3(String[] args) {
        //冒泡查找
        int[] array = new int[]{3,1,7,9,5};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));


    }
    public static void main2(String[] args) {
        //二分查找
        int[] arr = new int[]{1,2,4,5,6,9,12};
        int j = toFind(arr,6);
        System.out.println(j);
    }
    public static int toFind(int[] array,int i){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(i > array[mid]){
                left = mid + 1;
            }else if(i > array[mid]){
                right = mid + 1;
            }else{
                return mid;
            }
        }
        return -1;
    }
    public static void bubbleSort(int[] arr){
        for(int i = 0; i < arr.length - 1; i++){//运行多少次

            boolean flg = false;
            for(int j = 1; j < arr.length  - i; j++){//比较的个数
                if(arr[j - 1] > arr[j]){
                    int tep = arr[j -1];
                    arr[j -1] = arr[j];
                    arr[j] = tep;
                    flg = true;
                }
            }
            if(flg == false){//有序就直接跳出了
                break;
            }
        }
    }
    public static void reverse(int[] arr){
        int left = 0;
        int right = arr.length - 1;
        while(left < right){
            int tep = arr[left];
            arr[left] = arr[right];
            arr[right] = tep;
            left++;
            right--;
        }
    }
}
